package personal.causeless.driver.reader;

import java.io.File;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;


public abstract class DomReader{
	
	public DomReader(){}
	
	static final String ABSOLUTE_ROOT_LOCATION = "datas/elements/";
	
	static String ABSOLUTE_PATH_LOCATION ;
	
	private static Node node;
	
	private static class getValue{
		
		 static Node nodeValue(String nodeName){
			
			SAXReader saxReader = new SAXReader();
			
			Document document;
			try {
				document = saxReader.read(new File(ABSOLUTE_PATH_LOCATION));
				node = document.selectSingleNode("//"+nodeName);
				
			} catch (DocumentException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return node;
		}
		
	}
	
	public class methods{
		
		public By id(String id) throws NoSuchElementException{
						
			return By.id(getValue.nodeValue(id).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By className(String className)  throws NoSuchElementException{
			return By.className(getValue.nodeValue(className).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By cssSelector(String cssSelector) throws NoSuchElementException {
			return By.cssSelector(getValue.nodeValue(cssSelector).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By xpath(String xpath) throws NoSuchElementException {
			return By.xpath(getValue.nodeValue(xpath).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By linkText(String linkText) throws NoSuchElementException {
			return By.linkText(getValue.nodeValue(linkText).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By name(String name) throws NoSuchElementException {
			return By.name(getValue.nodeValue(name).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By tagName(String tagName) throws NoSuchElementException {
			return By.tagName(getValue.nodeValue(tagName).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}

		public By partialLinkText(String partialLinkText) throws NoSuchElementException {
			return By.partialLinkText(getValue.nodeValue(partialLinkText).valueOf("@"+Thread.currentThread().getStackTrace()[1].getMethodName()));
		}
		
	}

	// readers.vancl.id("index"); = By.id(Dom4j.getvalue("index"));
	// 
	

}
